/*
 * 短期离职预警 
 */
var url = '', jsonData = '';
$(function(){
	loadData();
});

function loadData(){
	loadTopCSS();
	/**
	 * 短期离职预警  he 下方表格
	 */
	/*loadShortLeaveOfficeEmployee();*/
	loadShortLeaveOfficeEmployeeTable();
	 
}

function loadTopCSS() {
	$("#li8").addClass("navdown");
}

function loadShortLeaveOfficeEmployeeTable(){
	url = ctx + '/employeeDimissionController/shortDimissionEmployee';
	
	var departmentId = $('#departmentId').val();
	var pageNum =0;
	jsonData = {departmentId:departmentId,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initShortLeaveOfficeEmployeeTable(returnData.data);
	$('#shortLeaveOfficeEmployee_tbody').html(tbodyHtml);
	
	/*
	 * 分页数据的设置
	 */
	
	$('#previousShortLeaveOfficeEmployeeInput').val(returnData.prePage);
	$('#nextShortLeaveOfficeEmployeeInput').val(returnData.nextPage);
	$('#lastShortLeaveOfficeEmployeeInput').val(returnData.lastPage);
	
	$('#curPageShortLeaveOfficeEmployee').html(returnData.curPage+1);
	$('#totalNumberShortLeaveOfficeEmployee').html(returnData.totalNumber);
	$('#totalPageShortLeaveOfficeEmployee').html(returnData.totalPage);
	$('#pageSizeShortLeaveOfficeEmployee').html(returnData.pageSize);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstShortLeaveOfficeEmployee').attr("disabled","disabled");
		$('#previousShortLeaveOfficeEmployee').attr("disabled","disabled");
	}else {
		$('#firstShortLeaveOfficeEmployee').removeAttr("disabled");
		$('#previousShortLeaveOfficeEmployee').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextShortLeaveOfficeEmployee').attr("disabled","disabled");
		$('#lastShortLeaveOfficeEmployee').attr("disabled","disabled");
	}else {
		$('#nextShortLeaveOfficeEmployee').removeAttr("disabled");
		$('#lastShortLeaveOfficeEmployee').removeAttr("disabled");
	}
	
}

function initShortLeaveOfficeEmployeeTable(data){
	var returnHtml = '';
	
	if (data.length == 0)
	returnHtml = '<tr><td colspan="5">暂无数据</td><td><a href="#">查看</a></td></tr>';
else
	$.each(data, function(index, item) {
		if(item.household_location==null){
			item.household_location=" ";
		}
		if(item.salary==null){
			item.salary=" ";
		}
		returnHtml += "<tr>"
				+ "<td title="+item.name+" style='text-align: center'>" + item.name + "</td>"
				+ "<td title="+item.gender+">"+item.gender+"</td>" 
				+ "<td title="+item.department+">" + item.department+ "</td>" 
				+ "<td title="+item.degree+">"+ item.degree + "</td>" 
				+ "<td title="+item.graduate_school+">"+ item.graduate_school + "</td>"
				+ "<td title="+item.household_location+">"+ item.household_location + "</td>"
				+ "<td title="+item.salary+">"+ item.salary
				+ "<td title="+item.job_number+"><a href='employeeDetailsController/talentInformationDetails?jobNumber="+item.job_number+"'>查看</a></td></tr>'";
		
	});
	
	
	return returnHtml;
}



/**
 * 短期离职员工 分页功能
 */
/*
 * 短期离职员工 分页功能    首页按钮
 */
function firstShortLeaveOfficeEmployee(){
	url = ctx + '/employeeDimissionController/shortDimissionEmployee';
	
	var departmentId = $('#departmentId').val();
	var pageNum=0;
	jsonData = {departmentId:departmentId,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initShortLeaveOfficeEmployeeTable(returnData.data);
	$('#shortLeaveOfficeEmployee_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousShortLeaveOfficeEmployeeInput').val(returnData.prePage);
	$('#nextShortLeaveOfficeEmployeeInput').val(returnData.nextPage);
	
	$('#curPageShortLeaveOfficeEmployee').html(returnData.curPage+1);
	$('#totalNumberShortLeaveOfficeEmployee').html(returnData.totalNumber);
	$('#totalPageShortLeaveOfficeEmployee').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstShortLeaveOfficeEmployee').attr("disabled","disabled");
		$('#previousShortLeaveOfficeEmployee').attr("disabled","disabled");
	}else {
		$('#firstShortLeaveOfficeEmployee').removeAttr("disabled");
		$('#previousShortLeaveOfficeEmployee').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextShortLeaveOfficeEmployee').attr("disabled","disabled");
		$('#lastShortLeaveOfficeEmployee').attr("disabled","disabled");
	}else {
		$('#nextShortLeaveOfficeEmployee').removeAttr("disabled");
		$('#lastShortLeaveOfficeEmployee').removeAttr("disabled");
	}
	
}

/*
 * 短期离职员工 分页功能    上一页按钮
 */
function previousShortLeaveOfficeEmployee(){
	url = ctx + '/employeeDimissionController/shortDimissionEmployee';
	
	var departmentId = $('#departmentId').val();
	
	var pageNum= $('#previousShortLeaveOfficeEmployeeInput').val();
	jsonData = {departmentId:departmentId,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initShortLeaveOfficeEmployeeTable(returnData.data);
	$('#shortLeaveOfficeEmployee_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousShortLeaveOfficeEmployeeInput').val(returnData.prePage);
	$('#nextShortLeaveOfficeEmployeeInput').val(returnData.nextPage);
	
	$('#curPageShortLeaveOfficeEmployee').html(returnData.curPage+1);
	$('#totalNumberShortLeaveOfficeEmployee').html(returnData.totalNumber);
	$('#totalPageShortLeaveOfficeEmployee').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstShortLeaveOfficeEmployee').attr("disabled","disabled");
		$('#previousShortLeaveOfficeEmployee').attr("disabled","disabled");
	}else {
		$('#firstShortLeaveOfficeEmployee').removeAttr("disabled");
		$('#previousShortLeaveOfficeEmployee').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextShortLeaveOfficeEmployee').attr("disabled","disabled");
		$('#lastShortLeaveOfficeEmployee').attr("disabled","disabled");
	}else {
		$('#nextShortLeaveOfficeEmployee').removeAttr("disabled");
		$('#lastShortLeaveOfficeEmployee').removeAttr("disabled");
	}
	
	
	
}

/*
 * 短期离职员工 分页功能    下一页按钮
 */
function nextShortLeaveOfficeEmployee(){
	url = ctx + '/employeeDimissionController/shortDimissionEmployee';
	
	var departmentId = $('#departmentId').val();
	
	var pageNum= $('#nextShortLeaveOfficeEmployeeInput').val();
	jsonData = {departmentId:departmentId,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initShortLeaveOfficeEmployeeTable(returnData.data);
	$('#shortLeaveOfficeEmployee_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousShortLeaveOfficeEmployeeInput').val(returnData.prePage);
	$('#nextShortLeaveOfficeEmployeeInput').val(returnData.nextPage);
	
	$('#curPageShortLeaveOfficeEmployee').html(returnData.curPage+1);
	$('#totalNumberShortLeaveOfficeEmployee').html(returnData.totalNumber);
	$('#totalPageShortLeaveOfficeEmployee').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstShortLeaveOfficeEmployee').attr("disabled","disabled");
		$('#previousShortLeaveOfficeEmployee').attr("disabled","disabled");
	}else {
		$('#firstShortLeaveOfficeEmployee').removeAttr("disabled");
		$('#previousShortLeaveOfficeEmployee').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextShortLeaveOfficeEmployee').attr("disabled","disabled");
		$('#lastShortLeaveOfficeEmployee').attr("disabled","disabled");
	}else {
		$('#nextShortLeaveOfficeEmployee').removeAttr("disabled");
		$('#lastShortLeaveOfficeEmployee').removeAttr("disabled");
	}
	
}

/*
 * 短期离职员工 分页功能   尾页按钮
 */
function lastShortLeaveOfficeEmployee(){
	url = ctx + '/employeeDimissionController/shortDimissionEmployee';
	
	var departmentId = $('#departmentId').val();
	
	var pageNum= $('#lastShortLeaveOfficeEmployeeInput').val();
	jsonData = {departmentId:departmentId,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initShortLeaveOfficeEmployeeTable(returnData.data);
	$('#shortLeaveOfficeEmployee_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousShortLeaveOfficeEmployeeInput').val(returnData.prePage);
	$('#nextShortLeaveOfficeEmployeeInput').val(returnData.nextPage);
	
	$('#curPageShortLeaveOfficeEmployee').html(returnData.curPage+1);
	$('#totalNumberShortLeaveOfficeEmployee').html(returnData.totalNumber);
	$('#totalPageShortLeaveOfficeEmployee').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstShortLeaveOfficeEmployee').attr("disabled","disabled");
		$('#previousShortLeaveOfficeEmployee').attr("disabled","disabled");
	}else {
		$('#firstShortLeaveOfficeEmployee').removeAttr("disabled");
		$('#previousShortLeaveOfficeEmployee').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextShortLeaveOfficeEmployee').attr("disabled","disabled");
		$('#lastShortLeaveOfficeEmployee').attr("disabled","disabled");
	}else {
		$('#nextShortLeaveOfficeEmployee').removeAttr("disabled");
		$('#lastShortLeaveOfficeEmployee').removeAttr("disabled");
	}
}


function commonAjax(){
	var result = '';
	$.ajax({
		type: 'GET',
		data: jsonData,
	    url: url,
	    async: false,
	    dataType:"json",
	    success: function(data){
	    	result = data;
	    },
	    error: function(){
	    }
	});
	return result;
}
/**
 *  ！！！！！！！！！！！异步请求！！！！！！！！！！！！！
 */
/*function commonAjax(fun, dataType){
	$.ajax({
		type: 'POST',
		data: jsonData,
	    url: url,
	    dataType: dataType,
	    success: function(data){
	    	fun(data);
	    },
	    error: function(){
	    }
	});
}*/